package com.caishi.lkx.common.mapper;

import cn.hutool.core.util.StrUtil;
import com.zzw.common.entity.IBSMapper;
import com.caishi.lkx.common.model.RedisCopyDataModel;

/**
 * @author by keray
 * date:2021/5/22 10:39 上午
 */
public interface RedisCopyDataMapper extends IBSMapper<RedisCopyDataModel, String> {

    default String data(String redisKey) {
        RedisCopyDataModel data = selectById(redisKey);
        return data == null ? null : data.getData();
    }

    default void addData(String redisKey, String data) {
        if (StrUtil.isBlank(data)) return;
        RedisCopyDataModel model = new RedisCopyDataModel();
        model.setId(redisKey);
        model.setData(data);
        if (contains(redisKey)) {
            updateById(model);
        } else {
            insert(model);
        }
    }
}
